package com.ug.system.controller;

import com.ug.common.constant.SecurityConstants;
import com.ug.common.response.ResponseMessage;
import com.ug.common.response.ResponseMessageFactory;
import com.ug.logs.annotation.Log;
import com.ug.system.entity.SysRoleMenu;
import com.ug.system.entity.dto.RoleMenuDto;
import com.ug.system.service.SysRoleMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author LY
 * @create 2024/7/17 10:06
 * @Description 角色菜单控制层
 */
@Tag(name = "SysRoleMenuController", description = "角色菜单管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys/role/menu")
public class SysRoleMenuController {

    private final SysRoleMenuService roleMenuService;

    /**
     * 通过角色ID获取对应的菜单
     * @param roleId 请求角色id入参
     */
    @Operation(summary = "获取角色菜单", security = { @SecurityRequirement(name = SecurityConstants.TOKEN_HEADER) })
    @Log("获取角色菜单")
    @GetMapping("/list")
    public ResponseMessage<List<SysRoleMenu>> getMenuByRoleId(@Parameter(description = "角色id") @RequestParam("roleId") Long roleId){
        return ResponseMessageFactory.getSuccessResponseMessage(roleMenuService.getMenuByRoleId(roleId));
    }

    /**
     * 授权角色菜单
     * @param roleMenuDto 请求角色菜单信息入参
     */
    @Operation(summary = "授权角色菜单", security = { @SecurityRequirement(name = SecurityConstants.TOKEN_HEADER) })
    @Log("授权角色菜单")
    @PostMapping("/edit")
    public ResponseMessage<String> editMenuRoleByRoleId(@RequestBody RoleMenuDto roleMenuDto){
        roleMenuService.editMenuRoleByRoleId(roleMenuDto);
        return ResponseMessageFactory.getSuccessResponseMessage("授权成功");
    }
}
